import request from '../utils/request';
import qs from 'qs';

//resource
export function getResource() {
  return request('/api/system/resource');
}
export function getAllResources() {
  return request('/api/system/allResource');
}
export function deleteResources(data) {
  return request('/api/system/deleteResource',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function addResource(data) {
  return request('/api/system/addOrUpdateResource',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}

//login
export function login(data) {
  return request("/api/index/login",{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function loginout() {
  return request("/api/index/logout",{
    method:'GET',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    }
  });
}
export function resetPswd(data) {
  return request("/api/system/resetPswd",{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}

//role
export function addOrUpdateRole(data) {
  return request('/api/system/addOrUpdateRole',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function deleteRoles(data) {
  return request('/api/system/deleteRole',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function getAllRoles() {
  return request('/api/system/allRole');
}
export function getRoleResource(data) {
  return request('/api/system/getRoleResource?roleId='+data.roleId,{
    method:'GET',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    }
  });
}
export function reBindRoleResource(data) {
  return request('/api/system/reBindRoleResource',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}


//admin
export function getAdminsPage(data) {
  return request(`/api/system/page/admins`);
}
export function getMyAdmins(data) {
  return request(`/api/system/my/admins?${qs.stringify(data)}`);
}
export function addOrUpdateAdmin(data) {
  return request('/api/system/addOrUpdateAdmin',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function deleteAdmins(data) {
  return request('/api/system/deleteAdmin',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function getAdminRoles(data) {
  return request('/api/system/adminRoles/'+data.adminId);
}

//file
export function getPageFiles(data) {
  return request(`/api/system/page/files?${qs.stringify(data)}`);
}
export function deleteFiles(data) {
  return request('/api/system/file/delete',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}


//customerType
export function addOrUpdateCustomerType(data) {
  return request('/api/system/updateCustomerType',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function deleteCustomerType(data) {
  return request('/api/system/deleteCustomerType',{
    method:'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
    body:JSON.stringify(data)
  });
}
export function getCustomerTypes() {
  return request('/api/system/customerTypes');
}
